package com.junxonline.instant.terminal.service.rpc;

import com.junxonline.instant.rpc.terminal.TerminalSendMessageRpcService;
import lombok.extern.log4j.Log4j2;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Log4j2
@DubboService
@Service
@Transactional
public class TerminalSendMessageRpcServiceImpl implements TerminalSendMessageRpcService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void sendMessage(String destination, String message) {
        // Rocket MQ异步队列处理
        log.info("RPC服务收到消息 => {} 消息队列目的地 => {}", message, destination);
        rocketMQTemplate.syncSend(destination, MessageBuilder.withPayload(message).build());
    }
}
